using System;
using System.Security.Cryptography;
using System.Text;
namespace Common.DEncrypt {
    public class DEncrypt {
        public static byte[] Decrypt(byte[] encrypted) {
            byte[] bytes = Encoding.Default.GetBytes("lecai");
            return Decrypt(encrypted, bytes);
        }

        public static string Decrypt(string original) {
            return Decrypt(original, "www.mou18.com1307012", Encoding.Default);
        }

        public static byte[] Decrypt(byte[] encrypted, byte[] byte_0) {
            TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
            provider.Key = MakeMD5(byte_0);
            provider.Mode = CipherMode.ECB;
            return provider.CreateDecryptor().TransformFinalBlock(encrypted, 0, encrypted.Length);
        }

        public static string Decrypt(string original, string string_0) {
            return Decrypt(original, string_0, Encoding.Default);
        }

        public static string Decrypt(string encrypted, string string_0, Encoding encoding) {
            try {
                byte[] buffer = Convert.FromBase64String(encrypted);
                byte[] bytes = Encoding.Default.GetBytes(string_0);
                return encoding.GetString(Decrypt(buffer, bytes));
            }
            catch {
                return "";
            }
        }

        public static byte[] Encrypt(byte[] original) {
            byte[] bytes = Encoding.Default.GetBytes("lecai");
            return Encrypt(original, bytes);
        }

        public static string Encrypt(string original) {
            return Encrypt(original, "www.mou18.com1307012");
        }

        public static byte[] Encrypt(byte[] original, byte[] byte_0) {
            TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
            provider.Key = MakeMD5(byte_0);
            provider.Mode = CipherMode.ECB;
            return provider.CreateEncryptor().TransformFinalBlock(original, 0, original.Length);
        }

        public static string Encrypt(string original, string string_0) {
            byte[] bytes = Encoding.Default.GetBytes(original);
            byte[] buffer2 = Encoding.Default.GetBytes(string_0);
            return Convert.ToBase64String(Encrypt(bytes, buffer2));
        }

        public static byte[] MakeMD5(byte[] original) {
            byte[] buffer = new MD5CryptoServiceProvider().ComputeHash(original);
            return buffer;
        }
    }
}

